/**
 * @author LKQ
 * @date 2021/12/26 12:43
 * @description 双指针法
 */
public class Solution2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        int[] height = {1, 8 , 6, 2, 5, 4, 8, 3, 7};
        solution2.maxArea(height);
    }

    public int maxArea(int[] height) {
        int left = 0, right = height.length - 1, ans = 0;
        while (left < right) {
            ans = Math.max(Math.min(height[left], height[right]) * (right - left), ans);
            // 每次移除最短的边
            if (height[left] < height[right]) {
                left++;
            }else {
                right--;
            }
        }
        return ans;
    }
}
